var mousePosition = {
    x:0,
    y:0
};
jQuery(document).bind('mousemove',function(e){ 
    mousePosition.x = e.pageX;
    mousePosition.y = e.pageY;
});
    
var T = window.setInterval(function(){
    if(window._gsTracker){
        window.clearInterval(T);
        _setSnapshotRegions(12,6);

    
        // 首页轮播图片 GridsumSnapshotID start
        _setSnapshotID(2,0);
        jQuery('#newsSlider .pagination li').mouseover(function(){
            var iGridsumSnapshotID = jQuery(this).find('a').attr('rel');
            _setSnapshotID(2,iGridsumSnapshotID);
        });
    
        var SliderT = window.setInterval(function(){
            var iGridsumSnapshotID = jQuery('#newsSlider .pagination li.active a').attr('rel');
            if(iGridsumSnapshotID == undefined){
                window.clearInterval(SliderT);
            }
            _setSnapshotID(2,iGridsumSnapshotID);
        }, 3500);//3500
    
        // 首页轮播图片 GridsumSnapshotID end
  
        // 导航 start
        _setSnapshotID(1,0);
        jQuery('#chromemenu li[class^="mm"]').mouseover(function(){
            var iGridsumSnapshotID = jQuery(this).attr('gridsumsnapshotid');
            _setSnapshotID(1,iGridsumSnapshotID);        
        });
    
        jQuery('.mt_box_wrap').mouseover(function(){
        
            var top = Number(jQuery(this).children('div').css('top').replace('px',''));
            var left= Number(jQuery(this).children('div').css('left').replace('px',''));
            var button = top +jQuery(this).children('div').height();
            var rigth= left+jQuery(this).children('div').width();

            var T = window.setTimeout(function(){
                if(mousePosition.y>top && mousePosition.y < button && mousePosition.x >left && mousePosition.x <rigth){
                    window.clearTimeout(T);
                }else{
                    window.clearTimeout(T);
                    _setSnapshotID(1,0);
                }
            },100)
        
            return true;
        })
    // 导航 end
    }
},50)
    
/**
 * @params {number} regionStateCounts 可变参数，每个参数表示区域的子状态数目，或者说子区域数目。
 * @return {boolean} 如果返回true表示状态组合没有超过255限制，允许这么配置。否则返回false。
 */
function _setSnapshotRegions(){
    _gsRegions = [];
    var sum = 1;
    for(var i = 0, len = arguments.length; i < len; i++){
        var num = Number(arguments[i]);
        if(isNaN(num)){
            return false;
        }
        sum *= num;
        _gsRegions.push({
            num:num,
            current:0
        });
    }
    return sum <= 255;
}
/**
 * 
 * @param {number}
 *            regionid 从1开始，0为特殊值，表示将整个页面作为一个唯一的一个大区域来看待。
 * @param {number}
 *            subregionid 从0开始，0一般表示该区域被隐藏掉时的状态。
 */
function _setSnapshotID(regionid, subregionid){
    regionid = Number(regionid);
    subregionid = Number(subregionid);
    if(regionid == 0){
        GridsumSnapshotID = subregionid; 
    }else if(window._gsRegions){
        regionid = regionid - 1;
        var region = _gsRegions[regionid];
        if(region){ 
            if(isNaN(subregionid) || subregionid >= region.num){
                return false;
            }
            region.current = subregionid;
            var snapshot = 0;
            for(var i = _gsRegions.length - 1; i > -1; i--){
                var m = _gsRegions[i].current;
                var sum = m;
                for(var j = i - 1; j > -1; j--){
                    sum *= _gsRegions[j].num;
                }
                snapshot += sum;
            }
            GridsumSnapshotID = snapshot;
        }
    } 
}

//首页BANNER轮播

var banner_img_witdh = 999;//780
var banner_img_animation_time = 500;
var banner_img_auto,banner_img,banner_img_length=0;
var banner_img_total = jQuery('.pagination li').length-1;
jQuery('.index_banner ul:eq(0)').css('width','3500px');//3500
jQuery('.index_banner ul:eq(0) li').each(function(i){
    jQuery(this).css('position', 'absolute').css('left',banner_img_witdh*i+'px');
})
jQuery('.pagination li').each(function(i){
    var number=i;    
    jQuery(this).hover(function(){        
        banner_animation(number);
        window.clearInterval(banner_img_auto);
    },function(){
        banner_img_auto = window.setInterval(function(){
            banner_animation(banner_img_length);
        },3000)
    }).attr('index', number);    
})

function banner_animation(number){

    if(number >= banner_img_total){
        banner_img = true;
    }else if(number == 0){
        banner_img = false;
    }
    jQuery('ul.pagination li').each(function(i){
        if(i == number){
            jQuery(this).css('opacity',1);
            jQuery(this).css('filter','alpha(opacity=100)');
        }else{
            jQuery(this).css('opacity','0.6');
            jQuery(this).css('filter','alpha(opacity=60)');
        }
    })
   
    jQuery('.index_banner ul li').each(function(i){
        jQuery(this).animate( {
            left: banner_img_witdh*(i-number) +"px"
        }, { 
            queue:false,
            duration: banner_img_animation_time
        } )            
    })
    if(banner_img){
        number--;
    }else{
        number++;
    }
    banner_img_length = number;
}
banner_img_auto = window.setInterval(function(){
    banner_animation(banner_img_length);
},3000)

//热词
jQuery('.index_nav div').hover(function(){
    jQuery(this).attr('class','index_nav_on');
},function(){
    jQuery(this).attr('class','index_nav_off');
                                                        
})

/*
var sub_title_t = new Array;
jQuery('.sub_title ul li a').mousemove(function(){
    jQuerythis = jQuery(this);
    jQuerythis.parent().attr('class','on')
    jQuery('#'+jQuery(this).attr('rel')).css('display','');
    jQuery('.index_nav').css('display','none');
}).mouseout(function(){
    jQuerythis = jQuery(this);
    jQuerythis.parent().attr('class','off')
    sub_title_t[jQuerythis.attr('rel')] = window.setTimeout(function(a){
        jQuery('#'+a.attr('rel')).css('display','none');
        jQuery('.index_nav').css('display','');
    }, 10,jQuery(this));
    
    jQuery('#'+jQuerythis.attr('rel')).hover(function(){
        window.clearTimeout(sub_title_t[jQuerythis.attr('rel')]);
    },function(){
        jQuery(this).css('display','none');
        jQuery('.index_nav').css('display','');
    })   
})*/